<?php

namespace App\Entities;

use App\Support\Database\Eloquent\UuidModel;
use Carbon\Carbon;

class ActivityInfo extends UuidModel
{
    const NOT_EXCHANGE = 0;
    const EXCHANGED = 1;

    public static function sync(Activity $activity)
    {
        $now = Carbon::now()->toDateTimeString();

        return self::query()->insert([
            'id' => $activity->getAttribute('id'),
            'name' => $activity->getAttribute('name'),
            'created_at' => $now,
            'updated_at' => $now,
        ]);
    }

    public function draws()
    {
        return $this->hasMany(DrawRecord::class, 'activity_id');
    }

    public function prize()
    {
        return $this->belongsToMany(
            Prize::class,
            'activity_prizes',
            'activity_id',
            'prize_id'
        );
    }

    public function prizeRecords()
    {
        return $this->hasMany(PrizeRecord::class, 'activity_id', 'id');
    }
}
